package com.witfortos.kotlindemo.mvvm.view_model

import androidx.lifecycle.MutableLiveData
import com.witfortos.common.base.BaseViewModel
import com.witfortos.common.utils.JsonParam
import com.witfortos.common.utils.SPUtils
import com.witfortos.kotlindemo.common.http.Req
import com.witfortos.kotlindemo.m.User

class LoginVm : BaseViewModel() {
    private val req by lazy {
        Req.getInstance()
    }
    var user = MutableLiveData<User>()

    fun login(username: String, password: String) {

        launchGo({
            user.value = request {
                val res = req.login(JsonParam().add("mobile", username).add("password", password).toString())
                SPUtils.getInstance().addCookie(res.data.thirdSession)
                req.getUserInfo()
            };
        })

    }
}